import java.util.Scanner;
import java.util.Random;
public class XiangmuText {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("请输入学生数目");
        int n = input.nextInt();
        input.nextLine();
        Xiangmu[] students = new Xiangmu[n];
        System.out.println("请依次输入学生姓名，学号，组别");
        for (int i = 0; i < n; i++) {
            System.out.print("姓名: ");
            String name = input.nextLine();
            System.out.print("学号: ");
            String no = input.nextLine();
            System.out.print("组别: ");
            int group = input.nextInt();
            input.nextLine();
            students[i] = new Xiangmu(name, no, group);
        }
        System.out.print("请选择抽取次数");
        int s = input.nextInt();
        input.nextLine();

        for (int i = 0; i < s; i++) {
            System.out.println("请选择抽取方式：1 - 姓名, 2 - 学号, 3 - 组别");
            int choice = input.nextInt();
            input.nextLine();
            Random rand = new Random();
            int num = rand.nextInt(n);
            switch (choice) {
                case 1:
                    System.out.println("抽取到的学生姓名为: "+students[num].sName);
                    break;
                case 2:
                    System.out.println("抽取到的学生学号为: "+students[num].sNo);
                    break;
                case 3:
                    System.out.println("抽取到的学生组别为: " +students[num].sGroup);
                    System.out.print("抽取到的学生为: " +students[num].sName);
                    for(int j = 0;j<n;j++){
                        if(students[j].sGroup == students[num].sGroup&&j!=num){
                            System.out.println(" "+students[j].sName);
                        }
                }
                    break;
                default:
                    System.out.println("无效的选择，请重新输入。");
            }
        }
    }
}

